//
//  MyBidJobDetailTabDetail.swift
//  ezyform
//
//  Created by MoennigQ on 11/2/19.
//  Copyright © 2019 Client.Solution Pty Ltd. All rights reserved.


import UIKit
import SnapKit
class ServiceDetailTabDetail: UIView {
    
    let scrollView = DIYScrollView()
    let contentView = UIView()
    //Job detail
    let jobDetailSectionView = ServiceDetailTabDetailSectionJobDetail()
    
    //assignee
    let assigneeSectionView = ServiceDetailTabDetailSectionAssignee()
    
    //publisher detail
    let publisherDetailSectionView = ServiceDetailTabDetailSectionPublishDetail()
    
    
    var picturesCollectionViewHeightConstant: Constraint?
    override func draw(_ rect: CGRect) {
        //此条件解决iOS 12会频繁调用draw方法导致UI混乱不堪，iOS 11没有这个问题
        if self.scrollView.superview == nil {
            self.scrollView.backgroundColor = .clear
            self.addSubview(self.scrollView)
            self.scrollView.snp.makeConstraints { (make) in
                make.edges.equalTo(self)
            }
            self.contentView.backgroundColor = UIColor(hexStr: Constant.SystemBackColor)
            self.scrollView.addSubview(contentView)
            self.contentView.snp.makeConstraints { (make) in
                make.top.bottom.equalTo(scrollView)
                make.left.right.equalTo(self)
            }
            //1.Job Detail
            let jobDetailLabel = ContentLabel(R.font.interRegular(size: 12), hexStr: "#292D3299")
            jobDetailLabel.text = "JOB DETAIL"
            self.contentView.addSubview(jobDetailLabel)
            jobDetailLabel.snp.makeConstraints { (make) in
                make.top.equalTo(20)
                make.left.equalTo(24)
                make.height.width.greaterThanOrEqualTo(0)
            }
            //
            self.contentView.addSubview(jobDetailSectionView)
            jobDetailSectionView.snp.makeConstraints { (make) in
                make.top.equalTo(jobDetailLabel.snp.bottom).offset(9)
                make.left.equalTo(12)
                make.right.equalTo(-12)
                make.height.greaterThanOrEqualTo(0)
            }
            //2.Assignee
            let assigneeTitle = ContentLabel(R.font.interRegular(size: 12), hexStr: "#292D3299")
            assigneeTitle.text = "ASSIGNEE"
            self.contentView.addSubview(assigneeTitle)
            assigneeTitle.snp.makeConstraints { (make) in
                make.top.equalTo(jobDetailSectionView.snp.bottom).offset(20)
                make.left.equalTo(jobDetailLabel)
                make.width.height.greaterThanOrEqualTo(0)
            }
            self.contentView.addSubview(assigneeSectionView)
            assigneeSectionView.snp.makeConstraints { (make) in
                make.top.equalTo(assigneeTitle.snp.bottom).offset(9)
                make.left.right.equalTo(jobDetailSectionView)
                make.height.greaterThanOrEqualTo(0)
                
            }
            //3. publish detail
            let publishDetailTitle = ContentLabel(R.font.interRegular(size: 12), hexStr: "#292D3299")
            publishDetailTitle.text = "PUBLISHER DETAIL"
            self.contentView.addSubview(publishDetailTitle)
            publishDetailTitle.snp.makeConstraints { (make) in
                make.top.equalTo(assigneeSectionView.snp.bottom).offset(20)
                make.left.equalTo(jobDetailLabel)
                make.width.height.greaterThanOrEqualTo(0)
            }
            //
            self.contentView.addSubview(publisherDetailSectionView)
            publisherDetailSectionView.snp.makeConstraints { (make) in
                make.top.equalTo(publishDetailTitle.snp.bottom).offset(9)
                make.left.right.equalTo(jobDetailSectionView)
                make.height.greaterThanOrEqualTo(0)
                make.bottom.equalTo(-20)
            }
        }
    }
    
    func setData(_ model: ServiceDetailModel){
        self.jobDetailSectionView.setData(model)
        self.publisherDetailSectionView.setData(model)
        self.assigneeSectionView.setData(model.installer_name)
    }
}

